#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve()
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    if(a == b) cout << 0 << endl;
    else if(a > b)
    {
        if(a == b + 1 && (a & 1)) cout << y << endl;
        else cout << -1 << endl;
    }
    else
    {
        if(x <= y) cout << (b - a) * x << endl;
        else
        {
            int k = (b - a) / 2;
            int ret = k * (x + y);
            if(k * 2 != b - a)
            {
                if(a & 1) ret += x;
                else ret += y;
            }
            cout << ret << endl;
        }
    }
}
signed main()
{
    int t; cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}